﻿using ff14bot;
using ff14bot.Enums;
using ff14bot.Managers;
using ff14bot.Objects;
using TreeSharp;
using Magitek.Helpers;
using ff14bot.Behavior;

namespace Magitek.Rotations
{
    class AllBasicClasses : Magitek
    {
        public override float PullRange
        {
            get { return WindowSettings.AllBasicClassespullrange; }
        }
        public override ClassJobType[] Class
        {
            get
            {
                return new[] {
                
                ClassJobType.Arcanist, 
                ClassJobType.Archer, 
                ClassJobType.Conjurer,
                ClassJobType.Gladiator, 
                ClassJobType.Lancer, 
                ClassJobType.Marauder, 
                ClassJobType.Pugilist, 
                ClassJobType.Thaumaturge 
            
            };
            }
        }
        public override void OnPulse() { }
        protected override Composite CreatePreCombatBuffs()
        {
            return new PrioritySelector(
                Extensions.SummonChocobo()
                );
        }
        protected override Composite CreateRest()
        {
            if (Core.Player.CurrentJob == ClassJobType.Conjurer || Core.Player.CurrentJob == ClassJobType.Arcanist ||
                Core.Player.CurrentJob == ClassJobType.Thaumaturge)
                return Extensions.DefaultRestBehavior(r => Core.Player.CurrentManaPercent);

            return Extensions.DefaultRestBehavior(r => Core.Player.CurrentTPPercent);
            
        }
        protected override Composite CreateHeal()
        {
            return new PrioritySelector(
                PartyHelper.AcquireTargetInformation(),
                
                Casting.Cast(r => "Summon", r => Core.Player.Pet == null && WindowSettings.AllBasicClassesUseAttacker, r => Core.Player, r => 13, r => false),
                Casting.Cast(r => "Summon II", r => Core.Player.Pet == null && WindowSettings.AllBasicClassesUseTank, r => Core.Player, r => 13, r => false),
 

                //Cleric stance if we want it.
                Casting.Cast(r => "Cleric Stance", r => (WindowSettings.SoloMode && !Core.Player.HasAura("Cleric Stance")) || (!WindowSettings.SoloMode && Core.Player.HasAura("Cleric Stance")), r => Core.Player, r => 3, r => false),

                //Level 30
                Casting.Cast(r => "Cure II", r => Core.Player.CurrentHealthPercent <= WindowSettings.AllBasicClassesCureIIHp, r => Core.Player, r => 3, r => false),

                //WhiteMage dispel
                Casting.Cast(r => "Esuna", r => PartyHelper.Dispeltarget != null && PartyHelper.Healtarget.CurrentHealthPercent > WindowSettings.HealingDispelAboveHp, r => PartyHelper.Dispeltarget, r => 3, r => false),

                //Level 18
                Casting.Cast(r => "Sustain", r => Core.Player.Pet != null && Core.Player.CurrentJob.ToString() == "Arcanist" && Core.Player.Pet.CurrentHealthPercent <= WindowSettings.AllBasicClassesHealPetHp && !Core.Player.Pet.HasAura("Sustain"), r => Core.Player.Pet, r => 3, r => true),

                //Level 8
                Casting.Cast(r => "Second Wind", r => Core.Player.CurrentHealthPercent <= WindowSettings.AllBasicClassesUseSecondWindHp, r => Core.Player, r => 3, r => false),

                //Level 6
                Casting.Cast(r => "Aetherflow", r => Core.Player.CurrentManaPercent <= WindowSettings.AllBasicClassesUseAetherflowMp, r => Core.Player, r => 3, r => false),
           
                //Level 4
                Casting.Cast(r => "Physick", r => Core.Player.CurrentHealthPercent <= WindowSettings.AllBasicClassesHealHp, r => Core.Player, r => 3, r => false),
                Casting.Cast(r => "Physick", r => Core.Player.Pet != null && Core.Player.CurrentJob.ToString() == "Arcanist" && Core.Player.Pet.CurrentHealthPercent <= 40, r => Core.Player.Pet, r => 3, r => false),

                //Level 2
                Casting.Cast(r => "Cure", r => Core.Player.CurrentHealthPercent <= WindowSettings.AllBasicClassesHealHp, r => Core.Player, r => 3, r => false),

                //Party Healing if enabled
                Casting.Heal(r => "Physick", r => PartyHelper.Healtarget != null && WindowSettings.AllBasicClassesHealParty && PartyHelper.Healtarget.CurrentHealthPercent < 80, r => PartyHelper.Healtarget, r => 3, r => true),
                Casting.Heal(r => "Cure", r => PartyHelper.Healtarget != null && WindowSettings.AllBasicClassesHealParty & PartyHelper.Healtarget.CurrentHealthPercent < 80, r => PartyHelper.Healtarget, r => 3, r => true)
            );
        }
        protected override Composite CreatePull()
        {
            return Combat.CreatePull(JobRange);
        }
        public float JobRange
        {
            get
            {
                if ((Core.Player.CurrentJob == ClassJobType.Lancer || Core.Player.CurrentJob == ClassJobType.Gladiator ||
                    Core.Player.CurrentJob == ClassJobType.Marauder || Core.Player.CurrentJob == ClassJobType.Pugilist)
                    && Core.Player.HasTarget)
                    return 3 + (Core.Player.CurrentTarget as BattleCharacter).CombatReach;
                else
                    return 24;
            }
        }
        protected override Composite CreateCombatBuffs()
        {
            return new PrioritySelector(ctx => Core.Player.CurrentTarget,
                new Decorator(ctx => ctx != null,
                new PrioritySelector(
                new Decorator(r => BotManager.Current.IsAutonomous, new PrioritySelector(
                CommonBehaviors.MoveToLos(ctx => ctx as GameObject),
                CommonBehaviors.MoveAndStop(ctx => (ctx as GameObject).Location, ctx => JobRange, true, "[Magitek] Moving in Range"))),

                //Pugilist 
                Casting.Cast(r => "Fists of Earth", r => !Core.Player.HasAura("Fists of Earth"), r => Core.Player, r => 3, r => true),
                Casting.Cast(r => "Featherfoot", r => Core.Player.CurrentHealthPercent <= WindowSettings.AllBasicClassesUseFeatherfootHp, r => Core.Player, r => 3, r => true),
                Casting.Cast(r => "Internal Release", r => WindowSettings.AllBasicClassesUseInternalRelease, r => Core.Player, r => 3, r => true),

                //Lancer
                Casting.Cast(r => "Keen Flurry", r => Core.Player.CurrentHealthPercent <= WindowSettings.AllBasicClassesUseKeenFlurryHp, r => Core.Player, r => 3, r => true),
                Casting.Cast(r => "Life Surge", r => WindowSettings.AllBasicClassesUseLifeSurge && Actionmanager.LastSpell.Name == "Vorpal Thrust", r => Core.Player.CurrentTarget, r => 3, r => true),

                //Marauder
                Casting.Cast(r => "Foresight", r => Core.Player.CurrentHealthPercent <= WindowSettings.AllBasicClassesUseForesightHp, r => Core.Player, r => 3, r => true),
                Casting.Cast(r => "Bloodbath", r => Core.Player.CurrentHealthPercent <= WindowSettings.AllBasicClassesUseBloodbathHp, r => Core.Player, r => 3, r => true),

                #region Marauder PVP
                Casting.Cast(r => "Blood for Blood", r => Core.Player.HasTarget && Core.Player.Distance(Core.Player.CurrentTarget.Location) <= 5, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Vengeance", r => Core.Player.CurrentHealthPercent <= WindowSettings.WarriorUseVengeanceHp, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Thrill Of Battle", r => Core.Player.CurrentHealthPercent < WindowSettings.WarriorUseThrillOfBattleHp, r => Core.Player, r => 2, r => false),
                #endregion

                //Archer
                Casting.Cast(r => "Hawk's Eye", r => WindowSettings.AllBasicClassesUseHawksEye, r => Core.Player, r => 3, r => true),
                Casting.Cast(r => "Raging Strikes", r => WindowSettings.AllBasicClassesUseRagingStrikes, r => Core.Player, r => 3, r => true),

                //Gladiator
                Casting.Cast(r => "Fight or Flight", r => WindowSettings.AllBasicClassesUseFightorFlight, r => Core.Player, r => 3, r => true),
                Casting.Cast(r => "Rampart", r => Core.Player.CurrentHealthPercent <= WindowSettings.AllBasicClassesUseRampartHp, r => Core.Player, r => 3, r => true),
                Casting.Cast(r => "Convalescence", r => Core.Player.CurrentHealthPercent <= WindowSettings.AllBasicClassesUseConvalescenceHp, r => Core.Player, r => 3, r => true)

                )));
        }
        protected override Composite CreateCombat()
        {
            return new PrioritySelector(ctx => Core.Player.CurrentTarget,
                new Decorator(ctx => ctx != null,
                new PrioritySelector(
                new Decorator(r => BotManager.Current.IsAutonomous, new PrioritySelector(
                CommonBehaviors.MoveToLos(ctx => ctx as GameObject),
                CommonBehaviors.MoveAndStop(ctx => (ctx as GameObject).Location, ctx => JobRange, true, "[Magitek] Moving in Range"))),

                Combat.DoPVP(),

                #region Marauder 30+ for PVP
                Casting.Cast(r => "Brutal Swing", r => (!WindowSettings.WarriorSaveBrutalSwing) || (WindowSettings.WarriorSaveBrutalSwing && WindowSettings._interruptList.Contains((Core.Player.CurrentTarget as BattleCharacter).SpellCastInfo.Name)), r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Storm's Path", r => Actionmanager.LastSpell.Name == "Maim" && Core.Player.CurrentTarget.HasAura("Storm's Eye", true), r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Storm's Eye", r => Actionmanager.LastSpell.Name == "Maim", r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Maim", r => Actionmanager.LastSpell.Name == "Heavy Swing" && Core.Player.ClassLevel == 50 && (!Core.Player.CurrentTarget.HasAura("Storm's Eye", true, 3000) || !Core.Player.CurrentTarget.HasAura("Storm's Path", true, 3000)), r => Core.Player.CurrentTarget, r => 2, r => false),
                #endregion

                #region 30 and below.
                //Level 30
                Casting.Cast(r => "Shield Swipe", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Windbite", r => !Core.Player.CurrentTarget.HasAura("Windbite", true), r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Phlemotomize", r => !Core.Player.CurrentTarget.HasAura("Phlebotomize", true), r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Butcher's Block", r => Actionmanager.LastSpell.Name == "Skull Sunder", r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Demolish", r => Core.Player.CurrentTarget.IsBehind && Core.Player.HasAura("Coeurl Form"), r => Core.Player.CurrentTarget, r => 3, r => false),

                //Level 26
                Casting.Cast(r => "Rage of Halone", r => Actionmanager.LastSpell.Name == "Savage Blade", r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Bio II", r => !Core.Player.CurrentTarget.HasAura("Bio II", true), r => Core.Player.CurrentTarget, r => 3, r => true),
                Casting.Cast(r => "Full Thrust", r => Actionmanager.LastSpell.Name == "Vorpal Thrust", r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Mercy Stroke", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),

                //Level18
                Casting.Cast(r => "Quick Nock", r => Extensions.EnemiesNearTarget(11) >= WindowSettings.AllBasicClassesTargetsToAOE && WindowSettings.AllBasicClassesUseAOE, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Twin Snakes", r => Core.Player.CurrentTarget.IsFlanking && Core.Player.HasAura("Raptor Form"), r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Maim", r => Actionmanager.LastSpell.Name == "Heavy Swing" && !Core.Player.HasAura("Maim"), r => Core.Player.CurrentTarget, r => 3, r => false),

                //Level 15
                Casting.Cast(r => "Repelling Shot", r => Core.Player.CurrentTarget.Distance(Core.Player.Location) < 5 && WindowSettings.AllBasicClassesUseRepellingShot, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Touch of Death", r => !Core.Player.CurrentTarget.HasAura("Touch of Death", true), r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Fluid Aura", r => Core.Player.CurrentTarget.Location.Distance(Core.Player.Location) < 6 && WindowSettings.AllBasicClassesUseFluidAura, r => Core.Player.CurrentTarget, r => 3, r => false),

                //Level 12
                Casting.Cast(r => "Riot Blade", r => Actionmanager.LastSpell.Name == "Fast Blade" && Core.Player.CurrentManaPercent <= WindowSettings.AllBasicClassesUseRiotBladeMana, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Bloodletter", r => true, r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Heavy Thrust", r => Core.Player.CurrentTarget.IsFlanking, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Virus", r => WindowSettings.AllBasicClassesUseVirus && !Core.Player.CurrentTarget.HasAura("Virus"), r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Overpower", r => Extensions.EnemiesNearTarget(8) >= WindowSettings.TargetsToAOE, r => Core.Player.CurrentTarget, r => 3, r => false),

                //Level 10
                Casting.Cast(r => "Miasma", r => !Core.Player.CurrentTarget.HasAura("Miasma", true), r => Core.Player.CurrentTarget, r => 3, r => true),
                Casting.Cast(r => "Haymaker", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),

                //Level 8
                Casting.Cast(r => "Flash", r => Extensions.EnemiesNearTarget(5) >= WindowSettings.TargetsToAOE && Core.Player.CurrentManaPercent > 30, r => Core.Player, r => 3, r => false),
                Casting.Cast(r => "Impulse Drive", r => Core.Player.CurrentTarget.IsBehind, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Energy Drain", r => Core.Player.CurrentManaPercent <= WindowSettings.AllBasicClassesUseEnergyDrainMp || Core.Player.CurrentHealthPercent <= WindowSettings.AllBasicClassesUseEnergyDrainHp, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Misery's End", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),

                //Level 6
                Casting.Cast(r => "Thunder", r => !Core.Player.CurrentTarget.HasAura("Thunder", true), r => Core.Player.CurrentTarget, r => 3, r=> true),
                Casting.Cast(r => "Fracture", r => !Core.Player.CurrentTarget.HasAura("Fracture", true) && WindowSettings.WarriorUseFracture, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Snap Punch", r => Core.Player.HasAura("Coeurl Form"), r => Core.Player.CurrentTarget, r => 3, r => false),

                //Level 4
                Casting.Cast(r => "Savage Blade", r => Actionmanager.LastSpell.Name == "Fast Blade", r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Skull Sunder", r => Actionmanager.LastSpell.Name == "Heavy Swing", r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Vorpal Thrust", r => Actionmanager.LastSpell.Name == "True Thrust", r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Venomous Bite", r => !Core.Player.CurrentTarget.HasAura("Venomous Bite", true), r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Aero", r => !Core.Player.CurrentTarget.HasAura("Aero", true), r => Core.Player.CurrentTarget, r => 3, r => false),

                //Level 2
                Casting.Cast(r => "Fire", r => Core.Player.CurrentManaPercent > 10, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Straight Shot", r => !Core.Player.HasAura("Straight Shot"), r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "True Strike", r => Core.Player.HasAura("Raptor Form"), r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Feint", r => !Core.Player.CurrentTarget.HasAura("Slow") && WindowSettings.AllBasicClassesUseFeint, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Bio", r => !Core.Player.CurrentTarget.HasAura("Bio", true), r => Core.Player.CurrentTarget, r => 3, r => true),

                //Level 1
                Casting.Cast(r => "Fast Blade", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Heavy Swing", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Heavy Shot", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "True Thrust", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Bootshine", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Blizzard", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Ruin", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Stone II", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Tomahawk", r => WindowSettings.WarriorUseTomahawk, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Stone", r => true, r => Core.Player.CurrentTarget, r => 3, r => false),
                Casting.Cast(r => "Shield Lob", r => MovementManager.IsMoving, r => Core.Player.CurrentTarget, r => 3, r => false)
            #endregion

            )));
        }
    }
}